package djboom.materials.display.page {
	import djboom.materials.events.InstructionEvent;
	import djboom.materials.state.Font;

	import org.casalib.display.CasaSprite;
	import org.casalib.display.CasaTextField;

	import flash.display.BlendMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.text.AntiAliasType;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	/**
	 * .
	 * <br>
	 * 
	 * @author DJ BooM 
	 * @since 06.04.2010
	 * 
	 */
	 
	/**
	 * Flex undocumnet hack for class visible a compile.
	 * 
	 */

	[Frame(extraClass="djboom.materials.display.page.Index")]

	[Frame(extraClass="djboom.materials.display.page.Authors")]

	[Frame(extraClass="djboom.materials.display.page.Navigation")]

	[Frame(extraClass="djboom.materials.display.page.Information")]

	[Frame(extraClass="djboom.materials.display.page.Tasks")]

	[Frame(extraClass="djboom.materials.display.page.Concepts")]

	[Frame(extraClass="djboom.materials.display.page.Test")]

	[Frame(extraClass="djboom.materials.display.page.work1.Page1")]

	[Frame(extraClass="djboom.materials.display.page.work1.Page2")]

	[Frame(extraClass="djboom.materials.display.page.work1.Page3")]

	[Frame(extraClass="djboom.materials.display.page.work1.Page4")]

	[Frame(extraClass="djboom.materials.display.page.work2.Page1")]

	[Frame(extraClass="djboom.materials.display.page.work2.Page2")]

	[Frame(extraClass="djboom.materials.display.page.work2.Page3")]
	[Frame(extraClass="djboom.materials.display.page.work2.Page4")]

	[Frame(extraClass="djboom.materials.display.page.work3.Page1")]

	[Frame(extraClass="djboom.materials.display.page.work3.Page2")]

	[Frame(extraClass="djboom.materials.display.page.work3.Page3")]

	[Frame(extraClass="djboom.materials.display.page.work3.Page4")]

	[Frame(extraClass="djboom.materials.display.page.Conclusion")]

	[Frame(extraClass="djboom.materials.display.page.ThanksPage")]

	[Frame(extraClass="djboom.materials.display.page.Literature")]

	public class Page extends CasaSprite {

		// ----------------------------------------------------------------------------
		// Константы класса.
		// ----------------------------------------------------------------------------

		private static const PAGES_PATH:String = "djboom.materials.display.page.";

		public static const INDEX:String = PAGES_PATH + "Index";
		public static const AUTHORS:String = PAGES_PATH + "Authors";
		public static const NAVIGATION:String = PAGES_PATH + "Navigation";
		public static const INFORMATION:String = PAGES_PATH + "Information";
		public static const TASKS:String = PAGES_PATH + "Tasks";
		public static const CONCEPTS:String = PAGES_PATH + "Concepts";
		public static const TEST:String = PAGES_PATH + "Test";
		public static const WORK_1_PAGE_1:String = PAGES_PATH + "work1.Page1";		public static const WORK_1_PAGE_2:String = PAGES_PATH + "work1.Page2";		public static const WORK_1_PAGE_3:String = PAGES_PATH + "work1.Page3";		public static const WORK_1_PAGE_4:String = PAGES_PATH + "work1.Page4";
		public static const WORK_2_PAGE_1:String = PAGES_PATH + "work2.Page1";		public static const WORK_2_PAGE_2:String = PAGES_PATH + "work2.Page2";		public static const WORK_2_PAGE_3:String = PAGES_PATH + "work2.Page3";		public static const WORK_2_PAGE_4:String = PAGES_PATH + "work2.Page4";
		public static const WORK_3_PAGE_1:String = PAGES_PATH + "work3.Page1";
		public static const WORK_3_PAGE_2:String = PAGES_PATH + "work3.Page2";
		public static const WORK_3_PAGE_3:String = PAGES_PATH + "work3.Page3";
		public static const WORK_3_PAGE_4:String = PAGES_PATH + "work3.Page4";		
		public static const CONCLUSION:String = PAGES_PATH + "Conclusion";		public static const THANKS_PAGE:String = PAGES_PATH + "ThanksPage";
		public static const LITERATURE:String = PAGES_PATH + "Literature";

		private static const DROPSHADOW_FILTER:DropShadowFilter = new DropShadowFilter(1, 90, 0xffffff, 1, 1, 1, 1, 1, false, true);

		/**
		 * Имен работ.
		 * 
		 */

		protected static const WORK1_NAME:String = "Определение средней плотности на образцах правильной геометрической формы";		protected static const WORK2_NAME:String = "Определение средней плотности на образцах неправильной геометрической формы";		protected static const WORK3_NAME:String = "Определение истинной плотности";

		// ----------------------------------------------------------------------------
		// Свойства класса.
		// ----------------------------------------------------------------------------

		private var _titleFormat:TextFormat;
		private var _titleField:CasaTextField;
		private var _titleFieldShadow:CasaTextField;
		private var _lockShape:CasaSprite;
		private var _counterFormat:TextFormat;
		private var _counterField:CasaTextField;

		// ----------------------------------------------------------------------------
		// Конструктор.
		// ----------------------------------------------------------------------------

		public function Page() {
			super();

			addEventListener(Event.REMOVED_FROM_STAGE, clearPage);
		}

		// ----------------------------------------------------------------------------
		// Приватные методы класса.
		// ----------------------------------------------------------------------------
		
		// ----------------------------------------------------------------------------
		// Видимые методы класса.
		// ----------------------------------------------------------------------------
                
		/**
		 * Заголовок страницы.
		 * 
		 * @param titleText: текст заголовка.
		 * 
		 */

		protected function createTitlePage(titleText:String):void {
			_titleFormat = new TextFormat(Font.MYRIAD_PRO_COND, 36, 0x002d47);
			_titleFormat.letterSpacing = 1;
            
			_titleFieldShadow = new CasaTextField();
			_titleFieldShadow.defaultTextFormat = _titleFormat;
			_titleFieldShadow.embedFonts = true;
			_titleFieldShadow.selectable = false;
			_titleFieldShadow.autoSize = TextFieldAutoSize.LEFT;            
			_titleFieldShadow.antiAliasType = AntiAliasType.ADVANCED;
			_titleFieldShadow.text = titleText;
			_titleFieldShadow.thickness = 100;
			_titleFieldShadow.x = 17;
			_titleFieldShadow.y = 18;
			_titleFieldShadow.alpha = 0.5;
			_titleFieldShadow.blendMode = BlendMode.OVERLAY;            
			_titleFieldShadow.filters = [DROPSHADOW_FILTER];
			addChild(_titleFieldShadow);
            
			_titleField = new CasaTextField();
			_titleField.defaultTextFormat = _titleFormat;
			_titleField.embedFonts = true;
			_titleField.selectable = false;
			_titleField.autoSize = TextFieldAutoSize.LEFT;            
			_titleField.antiAliasType = AntiAliasType.ADVANCED;
			_titleField.text = titleText;
			_titleField.thickness = 100;
			_titleField.x = 17;
			_titleField.y = 18;
			_titleField.alpha = 0.9;
			addChild(_titleField);
		}

		/**
		 * Заголовок работы.
		 * 
		 * @param titleText: текст заголовка.		 * @param workCounter: номер работы.
		 * 
		 */

		protected function createTitleWork(titleText:String, workCounter:int):void {
			_counterFormat = new TextFormat(Font.MYRIAD_PRO_COND, 18, 0xffffff);
            
			_counterField = new CasaTextField();
			_counterField.defaultTextFormat = _counterFormat;
			_counterField.embedFonts = true;
			_counterField.selectable = false;
			_counterField.autoSize = TextFieldAutoSize.LEFT;            
			_counterField.antiAliasType = AntiAliasType.ADVANCED;
			_counterField.text = "Работа " + workCounter;
			_counterField.thickness = 100;
			_counterField.x = 17;
			_counterField.y = 12;
			_counterField.scaleX = 1.2;
			_counterField.alpha = 0.5;
			addChild(_counterField);
            
			_titleFormat = new TextFormat(Font.MYRIAD_PRO_COND, 28, 0x002d47);
            
			_titleFieldShadow = new CasaTextField();
			_titleFieldShadow.defaultTextFormat = _titleFormat;
			_titleFieldShadow.embedFonts = true;
			_titleFieldShadow.selectable = false;
			_titleFieldShadow.autoSize = TextFieldAutoSize.LEFT;            
			_titleFieldShadow.antiAliasType = AntiAliasType.ADVANCED;
			_titleFieldShadow.text = titleText;
			_titleFieldShadow.thickness = 50;
			_titleFieldShadow.x = 17;
			_titleFieldShadow.y = 31;
			_titleFieldShadow.scaleX = 1.1;
			_titleFieldShadow.alpha = 0.5;
			_titleFieldShadow.blendMode = BlendMode.OVERLAY;            
			_titleFieldShadow.filters = [DROPSHADOW_FILTER];
			addChild(_titleFieldShadow);
            
			_titleField = new CasaTextField();
			_titleField.defaultTextFormat = _titleFormat;
			_titleField.embedFonts = true;
			_titleField.selectable = false;
			_titleField.autoSize = TextFieldAutoSize.LEFT;            
			_titleField.antiAliasType = AntiAliasType.ADVANCED;
			_titleField.text = titleText;
			_titleField.thickness = 50;
			_titleField.x = 17;
			_titleField.y = 31;
			_titleField.scaleX = 1.1;
			_titleField.alpha = 0.9;
			addChild(_titleField);
		}

		/**
		 * Блокировка страницы.
		 * 
		 */

		protected function lockPage():void {
			_lockShape = new CasaSprite();
			_lockShape.graphics.beginFill(0);
			_lockShape.graphics.drawRect(0, 0, 1018, 634);
			_lockShape.graphics.endFill();
			_lockShape.x = 3;
			_lockShape.y = 82;
			_lockShape.alpha = 0.6;
			_lockShape.blendMode = BlendMode.MULTIPLY;
			_lockShape.addEventListener(MouseEvent.CLICK, lockMouse);       
			addChild(_lockShape);
		}

		/**
		 * Разблокировка страницы.
		 * 
		 */

		protected function unlockPage():void {
			if (_lockShape != null) {
				_lockShape.destroy();
				_lockShape = null;
			}
		}

		/**
		 * Вызов функции с заданным именем.
		 * 
		 */

		protected function applyAuto(event:InstructionEvent):void {
			var method:Function = this[event.methodName] as Function;
			method.apply();
		}

		// ----------------------------------------------------------------------------
		// Обработчики событий.
		// ----------------------------------------------------------------------------

		private function lockMouse(event:MouseEvent):void {
		}

		protected function clearPage(event:Event):void {
			removeEventListener(Event.REMOVED_FROM_STAGE, clearPage);
            
			if (_titleField != null) {
				_titleField.destroy();
				_titleField = null;
			}
            
			if (_titleFieldShadow != null) {
				_titleFieldShadow.destroy();
				_titleFieldShadow = null;
			}
            
			if (_counterField) {
				_counterField.destroy();
				_counterField = null;
			}
            
			if (_lockShape != null) {
				_lockShape.destroy();
				_lockShape = null;
			}
			
			_titleFormat = null;
			_counterFormat = null;
		}

		// ----------------------------------------------------------------------------
		// Публичные методы.
		// ----------------------------------------------------------------------------

		public function init():void {
		}
	}
}
